<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common/include :: header('新增商品')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-goods-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商品名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="goodsName" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商品价格：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="goodsPrice" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商品数量：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="goodsNum" required>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">上架状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('business_goods_state')}">
                    <input type="radio" th:id="${dict.id}" name="state" th:value="${dict.value}"
                           th:checked="${dict.isDefault}">
                    <label th:for="${dict.id}" th:text="${dict.label}"></label>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">销售状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('business_goods_sale_state')}">
                    <input type="radio" th:id="${dict.id}" name="saleState" th:value="${dict.value}"
                           th:checked="${dict.isDefault}">
                    <label th:for="${dict.id}" th:text="${dict.label}"></label>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">热卖状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('business_goods_hot')}">
                    <input type="radio" th:id="${dict.id}" name="isHot" th:value="${dict.value}"
                           th:checked="${dict.isDefault}">
                    <label th:for="${dict.id}" th:text="${dict.label}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">所属窗口：</label>
            <div class="col-sm-8">
                <select name="windowId" class="form-control m-b">
                    <option th:each="item : ${windows}" th:text="${item.windowName}"
                            th:value="${item.id}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">封面图片：</label>
            <div class="col-sm-8">
                <input type="hidden" class="form-control" id="imageSrc" name="coverUrl">
                <img src="" width="50%" id="imgUrl">
                <br>
                <button type="button" class="imgBtn">浏览</button>
            </div>
        </div>
    </form>
</div>
<th:block th:include="common/include :: footer"/>
<th:block th:include="common/include :: datetimepicker"/>
<!-- 文件上传插件 -->
<link type="text/css" rel="stylesheet" href="/plugins/uploadifive/uploadifive.css"/>
<script type="text/javascript" src="/plugins/uploadifive/jquery.uploadifive.min.js"></script>
<!-- 富文本插件 -->
<script src="/plugins/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    var prefix = ctx + "/business/goods";
    //表单提交验证
    $(function () {
        //图片上传
        $('.imgBtn').uploadifive({
            'auto': true,  //自动发起图片上传请求
            'uploadScript': '/business/upload',   //处理上传文件的请求路径
            'buttonClass': "btn-link",
            'fileObjName': 'file',   //上传文件参数名
            'buttonText': '浏览...',
            'fileType': 'image',
            'multi': false,
            'fileSizeLimit': 5242880,
            'removeCompleted': true, //取消上传完成提示
            'uploadLimit': 1,
            //'queueSizeLimit'  : 10,
            'overrideEvents': ['onDialogClose', 'onError'],    //onDialogClose 取消自带的错误提示
            'onUploadComplete': function (file, data) {
                let result = JSON.parse(data);
                if (0 === result.code) {
                    $("#imgUrl").attr("src", result.url);
                    $("#imageSrc").val(result.url);
                    $.modal.msg("上传成功！");
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            onFallback: function () {
                $.modal.alertError("该浏览器无法使用!");
            }
        });
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-goods-add').serialize());
        }
    }
</script>
</body>
</html>
